/*Z OK seL4通过兼容Multiboot规范，与boot loader协作引导系统。这里定义的就是Multiboot header */

/*
 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230)
 *
 * SPDX-License-Identifier: GPL-2.0-only
 */

/* Configuration for MultiBoot, see MultiBoot Specification:
   www.gnu.org/software/grub/manual/multiboot
   We use a flags field of 3, indicating that we want modules loaded on page
   boundaries and access to the memory map information. We do not set bit 16,
   indicating that the structure of the image should be taken from its ELF
   headers. */
/*Z OS映像中供boot loader识别的Multiboot头 */
#include <config.h>
#include <machine/assembler.h>
/*Z 头记号。Multiboot记号是2开头 */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002

#ifdef CONFIG_MULTIBOOT_GRAPHICS_MODE_NONE
    #define MULTIBOOT_HEADER_FLAGS 3                /*Z 加载的用于辅助OS启动的模块要页对齐，传递可用内存信息 */
    #define MULTIBOOT_GRAPHICS_TEXT 0
#else /* CONFIG_MULTIBOOT_GRAPHICS_MODE_NONE */
    #define MULTIBOOT_HEADER_FLAGS 7                /*Z 除上述要求，还要传递显示模式信息 */
    #ifdef CONFIG_MULTIBOOT_GRAPHICS_MODE_TEXT
        #define MULTIBOOT_GRAPHICS_TEXT 1           /*Z 文本显示模式 */
    #else /* CONFIG_MULTIBOOT_GRAPHICS_MODE_TEXT */
        #define MULTIBOOT_GRAPHICS_TEXT 0           /*Z 图形显示模式 */
    #endif /* CONFIG_MULTIBOOT_GRAPHICS_MODE_TEXT */
#endif /* CONFIG_MULTIBOOT_GRAPHICS_MODE_NONE */

/* These configs will be set if a graphics mode is set. if they aren't
 * then we can put whatever in the multiboot header and it will be ignored.
 * This seems to be the easiest way to make things compile *//*Z 以下几项零值表示OS对显示模式的宽高深没有倾向 */
#ifndef CONFIG_MULTIBOOT_GRAPHICS_MODE_HEIGHT
#define CONFIG_MULTIBOOT_GRAPHICS_MODE_HEIGHT 0
#endif
#ifndef CONFIG_MULTIBOOT_GRAPHICS_MODE_WIDTH
#define CONFIG_MULTIBOOT_GRAPHICS_MODE_WIDTH 0
#endif
#ifndef CONFIG_MULTIBOOT_GRAPHICS_MODE_DEPTH
#define CONFIG_MULTIBOOT_GRAPHICS_MODE_DEPTH 0
#endif
/*Z OS映像的第一个段（节）*/
.section .mbh
#ifdef CONFIG_MULTIBOOT1_HEADER
    /* MultiBoot header */
    .align  4
    .long   MULTIBOOT_HEADER_MAGIC; /*magic*//*Z 用于boot loader识别出这个头 */
    .long   MULTIBOOT_HEADER_FLAGS; /*flags*//*Z 用于表示OS对boot loader的要求 */
    .long   - MULTIBOOT_HEADER_FLAGS - MULTIBOOT_HEADER_MAGIC; /*checksum*/
    .long   0 /*header_addr*//*Z ELF格式忽略这5项，a.out格式要填充以便boot loader加载内核映像 */
    .long   0 /*load_addr*/
    .long   0 /*load_end_addr*/
    .long   0 /*bss_end_addr*/
    .long   0 /*entry_addr*/
    .long   MULTIBOOT_GRAPHICS_TEXT /*mode_type*//*Z OS建议的显示模式。以下三项是建议的宽、高、深指标（单位：像素或字符） */
    .long   CONFIG_MULTIBOOT_GRAPHICS_MODE_WIDTH /*width*/
    .long   CONFIG_MULTIBOOT_GRAPHICS_MODE_HEIGHT /*height*/
    .long   CONFIG_MULTIBOOT_GRAPHICS_MODE_DEPTH /*depth*/
#endif
#ifdef CONFIG_MULTIBOOT2_HEADER
    .align  8
    __mbi2_start:
    /* magic multi-boot 2 header */
    .long   0xe85250d6                                  /*Z magic，用于boot loader识别出这个二版的头 */
    .long   0x0                                         /*Z architecture，0-i386，4-32位MIPS */
    .long   (__mbi2_end - __mbi2_start)                 /*Z header_length */
    .long  -(0xe85250d6 + (__mbi2_end - __mbi2_start))  /*Z checksum */
    /* end tag - type, flags, size */                   /*Z 以下为变长的tags，用于表示OS对boot loader的要求 */
    .word   0x0                                         /*Z type type=0,size=8标记的是结束tag */
    .word   0x0                                         /*Z flags */
    .long   0x8                                         /*Z size */
    __mbi2_end:
#endif
